package com.matrix.order.listener;

import com.matrix.common.constant.RocketMQConstants;
import com.matrix.order.application.OrderAppService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author 有点甜
 * @since 2025/7/29
 */
@Slf4j
@Component
@RequiredArgsConstructor
@RocketMQMessageListener(topic = RocketMQConstants.ORDER_PAY_TIMEOUT_TOPIC,
        consumerGroup = RocketMQConstants.ORDER_PAY_TIMEOUT_CONSUMER_GROUP)
public class OrderTimeoutListener implements RocketMQListener<String> {

    private final OrderAppService orderAppService;

    @Override
    public void onMessage(String orderNo) {
        log.info("收到订单支付超时检查消息,订单号: {}", orderNo);
        try {
            orderAppService.checkAndCloseTimeoutOrder(orderNo);
        } catch (Exception e) {
            log.error("处理订单支付超时消息失败", e);
        }
    }
}
